import { FMVCS } from "../../fgui/fmvc/FMVCS";
import GameMainVO from "./GameMainVO";
import { ConstDefine } from "../common/ConstDefine";
import Manager from "../../manager/Manager";

export default class GameMainData extends FMVCS.FData {
    /** 数据 */
    protected _vo: GameMainVO = new GameMainVO();
    get vo() { return this._vo; }
    /** 关卡地图配置 */
    config: { [key: string]: ConstDefine.Config.StarConfig } = null;
    /** 当前配置 */
    curConfig: ConstDefine.Config.StarConfig = null;

    constructor(){
        super();
        this.initConfig();
    }

    initConfig() {
        Manager.res.getConfigByName(`starconfig`).then((config: { [key: string]: ConstDefine.Config.StarConfig }) => {
            this.config = config;
        });
    }

    getCurConfig(){
        return this.config[this._vo.level];
    }

    reset(){
        this.vo.map = this.curConfig.map;
        this.vo.step = this.vo.pattern == ConstDefine.GameMain.Pattern.create ? 0 : this.curConfig.step;
        this.vo.offset = this.curConfig.offset;
        this.vo.answerStar = this.curConfig.answerStar;
        this.vo.mapID = this.curConfig.id.toString();
        this.vo.mapName = this.curConfig.mapName;
    }

    setLevelConfig(config: ConstDefine.Config.StarConfig){
        this.curConfig = config;
        this.reset();
    }

    /** 是否是关卡模式 */
    getIsNormal(){
        return this.vo.pattern == ConstDefine.GameMain.Pattern.normal;
    }

    /** 是否是创建模式 */
    getIsCreate(){
        return this.vo.pattern == ConstDefine.GameMain.Pattern.create;
    }

    /** 是否是修改模式 */
    getIsRivisions(){
        return this.vo.pattern == ConstDefine.GameMain.Pattern.rivisions;
    }

    /** 是否是自定义模式 */
    getIsCustom(){
        return this.vo.pattern == ConstDefine.GameMain.Pattern.custom;
    }

    /** 是否是创建或者修改模式 */
    getIsEdit(){
        return this.getIsCreate() || this.getIsRivisions();
    }

    /**
     * 获取下一关地图
     * @param pattern 游戏模式
     */
    getNextMap(pattern: ConstDefine.GameMain.Pattern){
        let map: ConstDefine.Config.StarConfig = null;
        switch(pattern){
            case ConstDefine.GameMain.Pattern.normal: {
                break;
            }
            case ConstDefine.GameMain.Pattern.custom: {

            }
        }
    }
}